package com.zx._12_算法.数据结构.stack;


/**
 * @version v1.0
 * @Project: knowledge
 * @Title: Stack3
 * @Description: Demo3 题的实现方式
 * @author: zhangxue
 * @date: 2019年7月23日下午10:11:46
 * @company: 未知之地
 * @Copyright: Copyright (c) 2019
 */
public class Stack3 {

    /**
     * 保存数据
     */
    private Stack2<Integer> dataStack = new Stack2<>();

    /**
     * 保存最小数据
     */
    private Stack2<Integer> minStack = new Stack2<>();

    public void push(Integer data) {
        dataStack.push(data);

        if (minStack.isEmpty()) {
            minStack.push(data);
        } else if (minStack.top() > data) {
            minStack.push(data);
        } else {
            minStack.push(minStack.top());
        }
    }


    @Override
    public String toString() {
        return "dataStack=" + dataStack + "\r\nminStack=" + minStack;
    }

    public Integer pop() {
        minStack.pop();
        return dataStack.pop();
    }

    public Integer min() {
        return minStack.top();
    }

}
